#include <bits/stdc++.h>

using namespace std;

struct TreeLinkNode {
    int val;
    struct TreeLinkNode *left;
    struct TreeLinkNode *right;
    struct TreeLinkNode *next;
    TreeLinkNode(int x) :val(x), left(NULL), right(NULL), next(NULL) {

    }
};

class Solution {
public:
    TreeLinkNode* GetNext(TreeLinkNode* pNode)
    {
        if(pNode==nullptr) return nullptr;
        TreeLinkNode *ans=nullptr;
        if(pNode->right!=nullptr){
            TreeLinkNode *r=pNode->right;
            while(r->left!=nullptr){
                r=r->left;
            }
            ans=r;
        }else{
            TreeLinkNode *ph=pNode->next,*ch=pNode;
            while(ph && ph->right==ch){
                ch=ph;
                ph=ph->next;
            }
            ans=ph;
        }
        return ans;
    }
};

int main(){




    return 0;
}